<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>消息群发管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
</head>
<body>
<div id="app">
    <div class="weui-cell" style="background-color: white">
        <div class="weui-cell__bd">
            <p v-if="isLine">当前状态:<span style="color: green;margin-left: 30px">在线</span></p>
            <p v-else>当前状态:<span style="color: red;margin-left: 30px">离线</span></p>
        </div>
    </div>
    <div class="weui-cells">
        <div class="weui-cells__title">群组列表（Id以@@开头则是生效的）</div>
        <div class="weui-cell" v-for="(v,k) in groups">
            <div class="weui-cell__bd">
                <p>{{k}}</p>
            </div>
            <div class="weui-cell__ft" style="max-width: 180px">ID:{{v}}</div>
        </div>
        <a href="javascript:;" class="weui-btn weui-btn_plain-primary" @click="updateGroups">更新群组</a>
    </div>

    <div class="weui-cells weui-cells_form">
        <div class="weui-cells__title">群发消息</div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <textarea class="weui-textarea" placeholder="请输入文本内容" rows="3" v-model="msgText"></textarea>
                <div class="weui-textarea-counter"></div>
            </div>
        </div>
    </div>
    <a href="javascript:;" class="weui-btn weui-btn_primary" @click="sendMsg">发送</a>
</div>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
<script>
    new Vue({
        el: "#app",
        data: {
            isLine: false,
            groups: [],
            msgText: '',
        },
        methods: {
            getLineStatus() {
                let _this = this;
                $.get("/login/status", function (status) {
                    _this.isLine = status;
                })
            },
            getGroups() {
                let _this = this;
                $.get("/msg/groups", function (data) {
                    _this.groups = data;
                })
            },
            updateGroups() {
                let _this = this;
                $.ajax({
                    url: "/msg/groups",
                    type: "PUT",
                    data: {},
                    success: function (data) {
                        _this.groups = data;
                        $.alert("请求成功")
                    },
                });
            },
            sendMsg() {
                $.post("/msg/groups", {text: this.msgText}, function (data) {
                    $.alert("发送成功");
                })
            }
        },
        created: function () {
            this.getLineStatus();
            this.getGroups();
        }
    })
</script>
</body>
</html>